package com.lwz.memento;

/**
 * 原发器
 * @author liuwangzhen
 *
 */
public class Originator {
	//原发器的状态
	private String state = "";
	
	/**
	 * 根据 传入的状态 创建对应的 备忘录对象
	 * @param state
	 * @return
	 */
	public Memento createMemento(String state){
		Memento memento = new MementoImpl(state);
		return memento;
	}
	
	public void setOriginatorStateByMemento(Memento memento){
		MementoImpl mementoImpl = (MementoImpl)memento;
		this.state = mementoImpl.getState();
	}
	/**
	 * 备忘录实现类
	 * @author liuwangzhen
	 *
	 */
	private class MementoImpl implements Memento{
		//需要保存的状态
		private String state;
		
		public MementoImpl(String state){
			this.state = state;
		}
		
		public String getState(){
			return this.state;
		}
	}

}
